package com.zy.rpc.provider.services;

import com.zy.rpc.api.FileService;
import com.zy.rpc.api.HelloService;
import com.zy.rpc.server.annotation.RpcService;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * @author zy
 * @date 2023/8/29 15:18
 */
public class FileServiceImpl implements FileService {

    /**
     * 对于刚上传的新文件 把他设置为hot文件
     * @param sourcePath
     * @param username
     * @throws IOException
     */
        @Override
        public void uploadFile(String sourcePath, String username) throws IOException {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://node01:8020");
            FileSystem fs = FileSystem.get(conf);
            Path localFilePath = new Path(sourcePath);
            String targetPath="/"+username+"/hot/";
            Path hdfsFilePath = new Path(targetPath);
            fs.copyFromLocalFile(localFilePath, hdfsFilePath);
            fs.close();
        }
    @Override
    public void downloadFile(String fileName) throws IOException {
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://node01:8020");
        FileSystem fileSystem = FileSystem.get(conf);
        fileSystem.copyToLocalFile(new Path("/input/mkdir/by/word.txt"), new Path("word.txt1"));
        fileSystem.close();
    }

}
